package com.newtouch.bxzs.business.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.product.model.*;
import com.newtouch.bxzs.business.product.service.ProductService;
import com.newtouch.bxzs.common.base.model.bo.PageParam;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产品的controller类
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/31 15:08</td>
 * <td>xiongdianqiang</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author xiongdianqiang
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "产品管理")
@RestController
@SuppressWarnings("unchecked")
@RequestMapping("/productController")
public class ProductController {
    /**
     * 静态变量：系统日志
     */
    private static final Log logger = LogFactory.getLog(ProductController.class);

    @Resource
    private ProductService productService;

    @ApiOperation(value = "展示产品列表")
    @PostMapping("/getProductList")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductList", userOperationType = 4, userOperationSummary = "展示产品列表")
    public BaseResponse<IPage<ProductBO>> getProductList(@RequestBody ProductVO productVO) {
        logger.info("展示产品列表");
        return RespGenerator.returnOK(productService.getProductList(productVO, true));
    }

    @ApiOperation(value = "查看产品详情")
    @ApiImplicitParam(name = "productId", value = "产品id", paramType = "String")
    @GetMapping("/getProductDetail")
    public BaseResponse<ProductDetailBO> getProductDetail(@RequestParam(value = "productId") String productId) {
        logger.info("查询产品详情");
        return RespGenerator.returnOK(productService.getProductDetail(productId));
    }

    @ApiOperation(value = "删除产品")
    @PostMapping("/deleteProduct")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/deleteProduct", userOperationType = 3, userOperationSummary = "删除产品")
    public BaseResponse<Integer> deleteProduct(@RequestBody @ApiParam(name = "productIds", value = "产品id集合", required = true) List<String> productIds) {
        logger.info("删除产品");
        return RespGenerator.returnOK(productService.deleteProduct(productIds));
    }

    @ApiOperation(value = "新增或者修改产品")
    @PostMapping("/modifyProduct")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/modifyProduct", userOperationType = 5, userOperationSummary = "新增或者修改产品")
    public BaseResponse<String> modifyProduct(@RequestBody ModifyProductVO modifyProductVO) {
        return RespGenerator.returnOK(productService.modifyProduct(modifyProductVO));
    }

    @ApiOperation(value = "修改产品发布状态")
    @PostMapping("/changeProductState")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/changeProductState", userOperationType = 2, userOperationSummary = "修改产品发布状态")
    public BaseResponse<Integer> changeProductState(@RequestBody ChangeStateVO changeStateVO) {
        logger.info("改变产品状态");
        return RespGenerator.returnOK(productService.changeProductState(changeStateVO));
    }

    @ApiOperation(value = "查看产品营销话术列表")
    @PostMapping("/getProductMarketingDiscourseList")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductMarketingDiscourseList", userOperationType = 4, userOperationSummary = "查看产品营销话术列表")
    public BaseResponse<IPage<ProductMarketingDiscourseBO>> getProductMarketingDiscourseList(@RequestBody ProductAppVO productAppVO) {
        logger.info("查看产品营销话术列表");
        return RespGenerator.returnOK(productService.getProductMarketingDiscourseList(productAppVO));
    }

    @ApiOperation(value = "查看产品营销话术详情")
    @ApiImplicitParam(name = "productId", value = "产品id", paramType = "String")
    @GetMapping("/getProductMarketingDiscourseDetail")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductMarketingDiscourseDetail", userOperationType = 4, userOperationSummary = "查看产品营销话术详情")
    public BaseResponse<ProductMarketingDiscourseDetailBO> getProductMarketingDiscourseDetail(@RequestParam(value = "productId") String productId) {
        logger.info("查看产品营销话术详情");
        return RespGenerator.returnOK(productService.getProductMarketingDiscourseDetail(productId));
    }

    @ApiOperation(value = "查看产品佣金比率列表")
    @PostMapping("/getProductCommissionRateList")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductCommissionRateList", userOperationType = 4, userOperationSummary = "查看产品佣金比率列表")
    public BaseResponse<IPage<ProductCommissionRateBO>> getProductCommissionRateList(@RequestBody PageParam pageParam) {
        logger.info("查看产品佣金比率列表");
        return RespGenerator.returnOK(productService.getProductCommissionRateList(pageParam));
    }

    @ApiOperation(value = "在App端查看产品列表")
    @PostMapping("/getProductListOnApp")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductListOnApp", userOperationType = 4, userOperationSummary = "查看产品列表")
    public BaseResponse<IPage<ProductOnAppBO>> getProductListOnApp(@RequestBody ProductAppVO productAppVO) {
        logger.info("在App端查看产品列表");
        return RespGenerator.returnOK(productService.getProductListOnApp(productAppVO));
    }

    @ApiOperation(value = "在App端根据所选保险公司查看产品列表")
    @PostMapping("/getProductListByCompany")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductListByCompany", userOperationType = 4, userOperationSummary = "App根据保险公司查看产品列表")
    public BaseResponse<IPage<ProductOnAppBO>> getProductListByCompany(@RequestBody ProductCompanyVO productCompanyVO) {
        logger.info("在App端根据所选保险公司查看产品列表");
        return RespGenerator.returnOK(productService.getProductListByCompany(productCompanyVO));
    }

    @ApiOperation(value = "按照产品名称排序查看产品列表")
    @PostMapping("/getProductListByMarketing")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductListByMarketing", userOperationType = 4, userOperationSummary = "根据产品名称排序查看产品列表")
    public BaseResponse<ProductListMarketingBO> getProductListByMarketing(@RequestBody ProductListByMarketingVO productListByMarketingVO) {
        logger.info("按照产品名称排序查看产品列表");
        return RespGenerator.returnOK(productService.getProductListByMarketing(productListByMarketingVO.getProductName()));
    }

    @ApiOperation(value = "展示产品选择列表")
    @PostMapping("/getProductChooseList")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductChooseList", userOperationType = 4, userOperationSummary = "展示产品选择列表")
    public BaseResponse<IPage<ProductBO>> getProductChooseList(@RequestBody ProductVO productVO) {
        logger.info("展示产品选择列表");
        return RespGenerator.returnOK(productService.getProductList(productVO, false));
    }

    @ApiOperation(value = "展示产品地区排名")
    @PostMapping("/getProductRegionRanking")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductRegionRanking", userOperationType = 4, userOperationSummary = "展示产品地区排名")
    public BaseResponse<ProductRegionRankingListBO> getProductRegionRanking(@RequestBody ProductRegionRankingVO productRegionRankingVO) {
        logger.info("展示产品地区排名");
        return RespGenerator.returnOK(productService.getProductRegionRanking(productRegionRankingVO));
    }

    @ApiOperation(value = "查询产品地区排名时展示产品列表")
    @PostMapping("/getProductRankingList")
    @MyLog(systemFunctionName = "产品管理", systemFunctionUrl = "/productController/getProductRankingList", userOperationType = 4, userOperationSummary = "查询产品地区排名时展示产品列表")
    public BaseResponse<RankingProductListBO> getProductRankingList(@RequestBody RankingProductListVO rankingProductListVO) {
        logger.info("查询产品地区排名时展示产品列表");
        return RespGenerator.returnOK(productService.getProductRankingList(rankingProductListVO));
    }
}
